<!DOCTYPE html>
<html lang="en">
<head>
    <title>测试消息</title>
    <meta http-equiv="Content-Type"content="text/html; charset=UTF-8">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js" type="text/javascript"></script>
    <!--<script type="text/javascript" src="${basePath}/js/plugins/mqttws31.js"></script>-->
    <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
</head>
    <body>
    <style type="text/css">
        .divcss5-a{margin:10px 0}
    </style>
        <div class="divcss5-a">
            <label>来自${userVO.phone!userVO.email}的消息</label>
        </div>
        <div class="divcss5-a">
            <label>接收消息:</label>
            <input type="text" id="message" height="500px" width="300px" /></br>
        </div>
        <div class="divcss5-a">
            <label>发送消息:</label>
            <input type="text" id="publish_message" name="publish_message"/>
            <button onclick="push_message()" >发送</button>
        </div>
        <input type="hidden" value="${userVO.id}" id="messageId"/>
        <script>
            var id = document.getElementById('messageId').value ;
            var client = new Paho.MQTT.Client("hellohang.win", 61614, id+"");
            /*订阅好友id,发送消息自己id*/
            if(id!="69"){
                client.onMessageArrived = function (msg) {
                    document.querySelector("#message").value = msg.payloadString;
                };
                client.connect({
                    onSuccess: function () {
                        client.subscribe("69");
                    }
                });

            }else{
                client.onMessageArrived = function (msg) {
                    document.querySelector("#message").value = msg.payloadString;
                };
                client.connect({
                    onSuccess: function () {
                        client.subscribe("32");
                    }
                });
            }
            function push_message() {
                var value = $("#publish_message").val();
                var message = new Paho.MQTT.Message(value);
                message.destinationName = id+"";
                client.send(message); // 发送消息
            }
        </script>
    </body>
</html>